//
//  ZYCNewsBulletionAnnexCell.m
//  ZDSC
//
//  Created by ZDTX on 2021/8/2.
//

#import "ZYCNewsBulletionAnnexCell.h"
#import "ZYCNewBulletinModel.h"
@interface ZYCNewsBulletionAnnexCell ()

@property (nonatomic, strong) UIImageView *annexImageView;
@property (nonatomic, strong) UILabel *annexLabel;
@property (nonatomic, strong) UIButton *downloadButton;
@end
@implementation ZYCNewsBulletionAnnexCell

- (void)setModel:(ZYCNoticeFileModel *)model{
    _model = model;
    _annexLabel.text = model.fileName;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = HEX_RGB(@"#FFFFFF");
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self.contentView addSubview:self.annexImageView];
        [self.contentView addSubview:self.annexLabel];
        [self.contentView addSubview:self.downloadButton];
        
        [self.annexImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).offset(15.0f);
            make.centerY.equalTo(self.contentView);
            make.size.mas_equalTo(CGSizeMake(35.0f, 40.0f));
        }];
        [self.annexLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.annexImageView.mas_right).offset(6.5f);
            make.right.equalTo(self.downloadButton.mas_left).offset(-21.0f);
            make.centerY.equalTo(self.annexImageView);
  
        }];
        [self.downloadButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.contentView).offset(-15.0f);
            make.centerY.equalTo(self.annexImageView);
            make.width.mas_equalTo(30.0f);
        }];

    }
    return self;
}

- (UIImageView *)annexImageView {
    if (!_annexImageView) {
        _annexImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"fujian"]];
    }
    return _annexImageView;
}

- (UILabel *)annexLabel {
    if (!_annexLabel) {
        _annexLabel = [UILabel LabelWithFont:kCustomFont(@"PingFangSC-Regular", 15.0f) titleColor:HEX_RGB(@"#92969D") textAlignment:ZZTextAlignmentLeft];
    }
    return _annexLabel;
}

- (UIButton *)downloadButton {
    if (!_downloadButton) {
        _downloadButton = [[UIButton alloc] init];
        _downloadButton.titleLabel.font =  kCustomFont(@"PingFangSC-Regular", 15.0f);
        NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:@"下载"];
        NSRange strRange = {0,[str length]};
        [str addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:strRange];
        [str addAttribute:NSForegroundColorAttributeName value:HEX_RGB(@"2079D3") range:strRange];
        [_downloadButton setAttributedTitle:str forState:UIControlStateNormal];//这个状态要加上
        [_downloadButton addTarget:self action:@selector(clickDownloadAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _downloadButton;
}

- (void)clickDownloadAction:(UIButton *)sender{
    if ([self.delegate respondsToSelector:@selector(newsBulletionAnnexCellDidDownload:)]) {
        [self.delegate newsBulletionAnnexCellDidDownload:self.model];
    }
}

@end
